﻿/**
 * @author sminutoli
 * version 1.0
 * 
 */
import com.dinmax.flash.utilities.string.StringUtils

class com.dinmax.flash.utilities.date.DateUtils {
	public static var date_DD_MM_AA:Number = 0;
	public static var date_DD_MM_AAAA:Number = 1;
	public static var date_MM_DD_AA:Number = 2;
	public static var hour_HH_MM:Number = 0;
	public static var hour_HH_MM_SS:Number = 1;
	public static var hour_HH_MM_SS_MS:Number = 2;
	public static var sep_DATE_DEFAULT = "/";
	public static var sep_HOUR_DEFAULT = ":";
	public static var sep_MINUTES_DEFAULT = ".";
	public static var sep_SECONDS_DEFAULT = ".";
	
	public static function dateToString(time:Date, type:Number, separator:String):String {
		
		if(type==undefined) type = date_DD_MM_AA;
		if(!separator) separator = sep_DATE_DEFAULT;
		switch (type){
			case date_DD_MM_AA:
			var sYear:String = String(time.getFullYear());
			sYear = sYear.substr(2);
			var sDate:String = StringUtils.fillString(String(time.getDate()), "0", 2);
			var sMonth:String = StringUtils.fillString(String(time.getMonth()+1), "0", 2);
			return sDate+separator+sMonth+separator+sYear;
			break;
			
			case date_DD_MM_AAAA:
			return time.getDate()+separator+time.getMonth()+separator+time.getFullYear();
			break;
			
			case date_MM_DD_AA:
			var sYear:String = String(time.getFullYear());
			sYear = sYear.substr(3);
			return time.getMonth()+separator+time.getDate()+separator+sYear;
			break;
		};
	};
	
	public static function hourToString(time:Date, type:Number, separators:Array):String {
		
		if(type == undefined) type = hour_HH_MM_SS;
		if(separators == undefined) separators = new Array(sep_HOUR_DEFAULT, sep_MINUTES_DEFAULT, sep_SECONDS_DEFAULT);
		if(separators[0] == undefined || separators[0] == "") separators[0] = sep_HOUR_DEFAULT;
		if(separators[1] == undefined || separators[1] == "") separators[1] = sep_MINUTES_DEFAULT;
		if(separators[2] == undefined || separators[2] == "") separators[2] = sep_SECONDS_DEFAULT;
		switch(type){
			case hour_HH_MM:
			var sHours:String = StringUtils.fillString(String(time.getHours()), "0", 2);
			var sMinutes:String = StringUtils.fillString(String(time.getMinutes()), "0", 2);
			return sHours+separators[0]+sMinutes;
			break;
			
			case hour_HH_MM_SS:
			trace("DateUtils.as | HH_MM_SS todavía no lo hice");
			break;
			
			case hour_HH_MM_SS_MS:
			trace("DateUtils.as | HH_MM_SS_MS todavía no lo hice");
			break;
		};
	};
	
	public static function milisecondsToString(mil:Number):String {
		var seconds:Number = Math.round(mil /1000);
		var minutes:Number = Math.floor(seconds / 60);
		if(minutes <= 0){
			var sMinutes:String = "00";
		} else if (minutes < 10) {
			var sMinutes:String = "0"+minutes;
		} else {
			var sMinutes:String = String(minutes);
		};
		var separator:String = ".";
		var restSeconds:Number = seconds - (minutes*60);
		if(restSeconds <= 0){
			var sSeconds:String = "00";
		} else if (restSeconds < 10){
			var sSeconds:String = "0"+restSeconds;
		} else {
			var sSeconds:String = String(restSeconds);
		};
		return sMinutes+separator+sSeconds;
	};
		
};